home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / LISTINGS / V_12_05 / ALLISON.ZIP / LOCAL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-04  |  420 b   |  36 lines

  1. LISTING 6 - Defines a Local class
  2. #include <iostream.h>
  3.  
  4. int i = 10;
  5.  
  6. main()
  7. {
  8.     void f();
  9.     f();
  10.     return 0;
  11. }
  12.  
  13. void f()
  14. {
  15.     static int j = 20;
  16.  
  17.     class Local
  18.     {
  19.         int k;
  20.     public:
  21.         Local(int i) : k(i) {}
  22.         void a() {cout << k+i << endl;}
  23.         void b() {cout << k+j << endl;}
  24.     };
  25.  
  26.     Local l(30);
  27.     l.a();
  28.     l.b();
  29. }
  30.  
  31. /* Output:
  32. 40
  33. 50
  34. */
  35.  
  36.